package com.pet.system.config;

import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.Collections;
import java.util.List;
@EnableCaching
@Configuration
@EnableAsync
@EnableScheduling
public class CacheManagerConfig {

	@Bean("cacheManager")
	// List<Cache>会主动搜索Cache的实现bean，并添加到caches中
	public CacheManager cacheManager(){
		SimpleCacheManager cacheManager = new SimpleCacheManager();
		cacheManager.setCaches(Collections.singletonList(new ConcurrentMapCache("loginCache")));

		return cacheManager;
	}


//	@Bean("loginCache")
	public ConcurrentMapCacheFactoryBean stockDetail(){
		ConcurrentMapCacheFactoryBean loginCache = new ConcurrentMapCacheFactoryBean();
		// 如果用户设置名称为stockDetail的缓存，则需要添加这样的一个bean
		loginCache.setName("loginCache");

		return loginCache;
	}



}
